package com.suray.rgv60.util;

import com.suray.type.ErrorLevel;

/**
 * 两栖车自定义异常
 */
public enum Rgv60ErrorUtil {
    PERFORM_TASK_ERROR(1000, "任务执行失败", ErrorLevel.ERROR_LEVEL_WCS),
    ROUTE_ERROR(1001, "导航失败", ErrorLevel.ERROR_LEVEL_WCS),
    NOT_EXIST_TASK(1002, "不存在该任务，无法执行动作", ErrorLevel.ERROR_LEVEL_WCS),
    NO_POSITION(1003, "当前坐标为空，不能执行任务", ErrorLevel.ERROR_LEVEL_WCS),
    TASK_START_NODE_FAULT(1004, "起点位置与小车当前位置不一致", ErrorLevel.ERROR_LEVEL_WCS),
    ROBOT_POSITION_ERROR(1005, "小车定位不正确", ErrorLevel.ERROR_LEVEL_WCS),
    CHANGE_MAP_FAIL(1006, "地图切换失败", ErrorLevel.ERROR_LEVEL_WCS),
    SYSTEM_SET_ERROR(2000, "外部设置故障", ErrorLevel.ERROR_LEVEL_WCS),
    INTERRUPT_RGV(2001, "中断小车", ErrorLevel.ERROR_LEVEL_WCS),
    DEFAULT_ERROR(9000, "故障", ErrorLevel.ERROR_LEVEL_WCS);
    ;

    int code;
    String des;
    ErrorLevel level;
    Rgv60ErrorUtil(int code, String des, ErrorLevel level) {
        this.code = code;
        this.des = des;
        this.level = level;
    }

    public int getCode() {
        return code;
    }

    public String getDes() {
        return des;
    }

    public ErrorLevel getLevel() {
        return level;
    }

    public static Rgv60ErrorUtil parseCode(int code) {
        for (Rgv60ErrorUtil rgvErrorUtil : Rgv60ErrorUtil.values()) {
            if (rgvErrorUtil.code == code) {
                return rgvErrorUtil;
            }
        }

        throw new RuntimeException("不存在的异常码：" + code);
    }

    @Override
    public String toString() {
        return "{" +
                "异常码=" + code +
                ", '" + des + '\'' +
                ", " + level +
                '}';
    }
}
